package com.lonwin.inspectionmanagement.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lonwin.inspectionmanagement.R;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.UserBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: zhangjing
 * DATA:2018/12/25 7:15 PM
 * DESC:
 * email:zhangjingworkmol@163.com
 */
public class UserAdapter extends BaseQuickAdapter<UserBean.DatasBean,BaseViewHolder> {
    public UserAdapter( @Nullable List<UserBean.DatasBean> data) {
        super(R.layout.item_user_info, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, UserBean.DatasBean item) {
        helper.<CheckBox>getView(R.id.cb_isSelected).setChecked(item.isSelected());
        helper.setText(R.id.tv_name,item.getNameX());
        helper.setText(R.id.tv_id,item.getRoleNameStr());
        helper.setText(R.id.tv_location,item.getPosition());
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.setSelected(!item.isSelected());
                notifyItemChanged(helper.getLayoutPosition());
            }
        });
//        helper.<CheckBox>getView(R.id.cb_isSelected).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                item.setSelected(!item.isSelected());
//                notifyItemChanged(helper.getLayoutPosition());
//            }
//        });
    }

    public List<UserBean.DatasBean> getSelectedUser(){
        List<UserBean.DatasBean> userBeans=new ArrayList<>();
        for (UserBean.DatasBean item:mData){
            if (item.isSelected()){
                userBeans.add(item);
            }
        }
        return userBeans;
    }
}
